#!/usr/bin python3
# -*- coding:UTF-8 -*-
# Author: nigo
import pandas as pd

df = pd.DataFrame({
    "A": ["foo", "foo", "foo", "foo", "foo", "bar", "bar", "bar", "bar"],
    "B": ["one", "one", "one", "two", "two", "one", "one", "two", "two"],
    "C": [
        "small", "large", "large", "small", "small", "large", "small", "small",
        "large"
    ],
    "D": [1, 2, 2, 3, 3, 4, 5, 6, 7],
    "E": [2, 4, 5, 5, 6, 6, 8, 9, 9]
})

table = df.pivot_table(values=['D', 'E'],
                       index=['A', 'C'],
                       aggfunc={
                           'D': 'mean',
                           'E': ['min', 'max', 'mean']
                       })
print(df)
print(table)
